<template>
	<view class="content">
		<view class="padding-about-30 padding-top-30">
			<view class="background">
				<view class="padding-top-30 display-flex space-between align-items">
					<view class="color-FFF display-flex flex-direction-column center align-items margin-left-40 ">
						<view class="font-size-22">
							卡库存（张）
						</view>
						<view class="font-size-36 font-weight-bold">
							{{info?.user.show_card_count.card_all}}
						</view>
					</view>
					<view class="">
						<view @click="navigateTo('/pages/my/cardTransfer/cardTransfer')" class="button margin-right-30">
							转卡
						</view>
						<view  @click="navigateTo('/pages/my/Cardtransferrecord/Cardtransferrecord')" class="button margin-top-10 margin-right-30">
							转卡记录
						</view>
					</view>
				</view>
			</view>
			<view class="margin-top-30 view">
				<view  class="display-flex space-between align-items">
					<view @click="datetimePicker.open()" class="">
						<view class="font-size-22">
							开始日期
						</view>
						<view class="time margin-top-10 display-flex align-items">
							<view class="file-1 margin-left-10 font-size-22 ">
								{{date}}
							</view>
							<view class="margin-right-10">
								<uv-icon name="arrow-down-fill" color="#2671CE" size="12"></uv-icon>
							</view>
						</view>
					</view>

					<view @click="enddatetimePicker.open()" class="margin-left-30">
						<view class="font-size-22">
							结束日期
						</view>
						<view class="time margin-top-10 display-flex align-items">
							<view class="file-1 margin-left-10 font-size-22 ">
								{{edndate}}
							</view>
							<view class="margin-right-10">
								<uv-icon name="arrow-down-fill" color="#2671CE" size="12"></uv-icon>
							</view>
						</view>
					</view>
					<view class="font-size-22 margin-left-30">
						<view class="">
							开卡：{{info?.in}}
						</view>
						<view class="">
							转出：{{info?.out}}
						</view>
					</view>
				</view>
				<uv-tabs @click="tabs" :list="tabslist" lineWidth="20" :activeStyle="{
			color: '#303133',
			fontWeight: 'bold',
			transform: 'scale(1.05)'
    	}" :inactiveStyle="{
			color: '#606266',
			transform: 'scale(1)'
		}" itemStyle="width:20%; height: 34px;"></uv-tabs>
				<view class="">
					<view v-for="item,iindex in list" class="">
						<view class="display-flex space-between align-items" style="padding:20rpx 0;">
							<view class="">
								<view class="font-size-26 file-1">
									{{item.msg}}
								</view>
								<view class="font-size-22 margin-top-10 color-999">
									{{timestampToDate(item.createtime * 1000,'Y-m-d')}}
								</view>
							</view>
							<view style="color: #40AD35;" class="margin-right-10 font-size-26">
								{{item.card_num}}
							</view>
						</view>
						<uv-gap height="1" bgColor="#F5F5F5"></uv-gap>
					</view>
				</view>
			</view>
			<div class="kong"></div>
		</view>
		<uv-datetime-picker ref="datetimePicker" v-model="value" mode="date" :maxDate="Date.now()" @confirm="confirm">
		</uv-datetime-picker>
		<uv-datetime-picker ref="enddatetimePicker" v-model="value" mode="date" :maxDate="Date.now()"
			@confirm="ednconfirm">
		</uv-datetime-picker>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		nativeUI,
		navigateTo,
		navigateBack,
		timestampToDate
	} from '@/utils/index.js';
	import * as api from '@/request/app.js'; // 引入api 方法
	import local from '@/utils/localStorage.js'; //引入本地存储方法
	const value = ref(Date.now())
	const tabslist = ref([{
		name: '全部',
		tab: 'all'
	}, {
		name: '转入',
		tab: 'card_in'
	}, {
		name: '转出',
		tab: 'card_out'
	}, {
		name: '开卡',
		tab: 'card_open'
	}])
	const tab = ref('all')
	const date = ref(timestampToDate(Date.now(), 'Y/m/d'))
	const edndate = ref(timestampToDate(Date.now(), 'Y/m/d'))
	const datetimePicker = ref(null)
	const enddatetimePicker = ref(null)
	const info = ref({})
	//分页
	const pagingState = ref(false)
	const page = ref(1)
	const list = ref([])
	onLoad(function(option) {
		
	});
	onShow(function() {card_log()});

	function tabs(event) {
		tab.value = event.tab
		//分页
		pagingState.value = false
		page.value = 1
		list.value = []
		card_log()
	}

	function confirm(event) {
		date.value = timestampToDate(event.value, 'Y/m/d')
		pagingState.value = false
		page.value = 1
		list.value = []
		card_log()
	}

	function ednconfirm(event) {
		edndate.value = timestampToDate(event.value, 'Y/m/d')
		pagingState.value = false
		page.value = 1
		list.value = []
		card_log()
	}
	async function card_log() {
	
		let object = {
			page: page.value,
			tab: tab.value,
			begin_time: date.value,
			end_time: edndate.value,
		}
		if (!pagingState.value) {
			const {
				code,
				data
			} = await api.card_log(object)
	
			info.value = data
			list.value = list.value.concat(data.list.data)
			console.log(list.value);
			if (data.list.current_page == data.list.last_page) {
				pagingState.value = true
				return
			}
			page.value++
		}
	}
	onReady(function() {});
	onReachBottom(function() {
		card_log()
	});
</script>

<style scoped lang="scss">
	.time {
		width: 173rpx;
		height: 66rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		border: 1px solid #C3DAFC;
	}

	.view {
		padding: 25rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
	}

	.button {
		width: 122rpx;
		height: 42rpx;
		background: #F8F8F7;
		border-radius: 21rpx;
		border: 1px solid #C3DAFC;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 22rpx;
		color: #2671CE;
	}

	.background {
		width: 690rpx;
		height: 182rpx;
		background-size: 100% 100% !important;
		background-repeat: no-repeat;
		background: url('/static/ktjbg.png');
	}
</style>